//
// SoapTrace.Net - A soap message monitoring utility.
//
// Copyright (C) 2004 Matthew Ward
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Matthew Ward (mrward@users.sourceforge.net)

using SoapTrace.Core.Formatters;
using System;
using System.IO;
using NUnit.Framework;

namespace SoapTrace.Tests
{
	/// <summary>
	/// Tests that we can load a string into the 
	/// <see cref="SoapTrace.Core.Formatters.WebServicesDescriptionLanguageFile"/>
	/// class.</summary>
	[ TestFixture ]
	public class LoadWsdlFileFromStringTestFixture
	{
		/// <summary>
		/// Tests that we can load a string into the 
		/// <see cref="SoapTrace.Core.Formatters.WebServicesDescriptionLanguageFile"/>
		/// class.
		/// </summary>
		[ Test ]
		public void LoadString( )
		{
			StringReader Reader = new StringReader( GetWsdlText( ) );
			
			WebServicesDescriptionLanguageFile Wsdl = new WebServicesDescriptionLanguageFile( );
			
			Wsdl.Load( Reader );
			
			Assert.AreEqual( "TestEJB", 
			                Wsdl.WebService.Name, 
			                "Web service name is incorrect." );
		}
		
		private string GetWsdlText( )
		{
			string Wsdl = "<definitions xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:tns='urn:Test' xmlns:s='http://www.w3.org/2001/XMLSchema' xmlns:http='http://schemas.xmlsoap.org/wsdl/http/' xmlns:tm='http://microsoft.com/wsdl/mime/textMatching/' xmlns:mime='http://schemas.xmlsoap.org/wsdl/mime/' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' targetNamespace='urn:Test' xmlns='http://schemas.xmlsoap.org/wsdl/'>" +
			  " <types />" +
			  " <message name='FooSoapIn'>" +
			  "   <part name='string' type='s:string' />" +
			  " </message>" +
			  " <message name='FooSoapOut'>" +
			  "   <part name='string' type='s:string' />" +
			  " </message>" +
			  " <portType name='TestEJBSoap'>" +
			  "  <operation name='Foo'>" +
			  "    <input message='tns:FooSoapIn' />" +
			  "    <output message='tns:FooSoapOut' />" +
			  "    </operation>" +
			  "  </portType>" +
			  "  <binding name='TestEJBSoap' type='tns:TestEJBSoap'>" +
		 	  "   <soap:binding transport='http://schemas.xmlsoap.org/soap/http' style='document' />" +
			  "   <operation name='Foo'>" +
			  "     <soap:operation soapAction='urn:Compress' style='rpc' />" +
			  "     <input>" +
			  "       <soap:body use='encoded' namespace='java:net.soaptrace.webservices.TestEJB' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' />" +
			  "     </input>" +
			  "     <output>" +
			  "       <soap:body use='encoded' namespace='java:net.soaptrace.webservices.TestEJB' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' />" +
			  "     </output>" +
			  "   </operation>" +
			  " </binding>" +
			  " <service name='TestEJB'>" +
			  "   <port name='TestEJBSoap' binding='tns:TestEJBSoap'>" +
			  "     <soap:address location='http://127.0.0.1/Test.asmx' />" +
			  "    </port>" +
			  "  </service>" +
			  "</definitions>";
			
			return Wsdl;
		}
	}
}
